#-------------------------------------------------------------------------------
# Name:        common
# Purpose:
#
# Author:      SUPER_紫电  QQ:911344755
#
# Created:     16/08/2022
# Copyright:   (c) SUPER_紫电 2022 All rights reserved.
# Licence:     <Modified BSD licence>
#-------------------------------------------------------------------------------

backupdir = ''
tempdir = '\\Temp'
workdir = ''

def is_64bit_os():
    import os
    if "PROCESSOR_ARCHITEW6432" in os.environ:
        if os.environ["PROCESSOR_ARCHITEW6432"] == "AMD64":
            return True
    if "64" in os.environ["PROCESSOR_ARCHITECTURE"]:
        return True
    return False

def get_file_dir():
    import os
    try:
        dirname = os.path.dirname(__file__)
    except:
        import inspect
        dirname = os.path.dirname(inspect.getsourcefile(lambda:0))
    return dirname

def get_startup_dir():
    import os, sys
    path = os.path.dirname(sys.argv[0])
    if path == '': path = '.\\'
    return path

def add_startup_dir():
    import sys
    sys.path.append(get_startup_dir())

def save_log(filename, text):
    try:
        with open(filename, 'w', encoding='utf-8') as file:
            file.write(text)
        return True
    except:
        return False

def import_module(module_name):
    import importlib
    try:
        module = importlib.import_module(module_name)
        return module
    except:
        return None

def reload_module(module_name):
    import importlib
    try:
        module = importlib.import_module(module_name)
        modele = importlib.reload(module)
        return module
    except:
        return None

def rewrite_file(file_name, file_name_ext):
    try:
        with open(file_name_ext, 'r', encoding='utf-8') as ext:
            with open(file_name, 'w', encoding='utf-8') as f:
                f.write(ext.read())
            return True
    except:
        return False
